/**
* 支付管理 支付配置信息
*/
<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>会议室管理</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 搜索筛选 -->
    <el-form :inline="true" :model="formInline" class="user-search">
      <el-form-item label="搜索：">
        <el-input size="small" v-model="formInline.roomCodeOrName" placeholder="输入会议室编码或名称" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-select size="small" v-model="formInline.roomType" placeholder="选择会议室大小" class="userRole" clearable>
          <el-option v-for="type in roomType" :label="type.key" :value="type.value" :key="type.value"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-select size="small" v-model="formInline.enableStatus" placeholder="选择会议室状态" class="userRole" clearable>
          <el-option v-for="type in enableStatus" :label="type.key" :value="type.value" :key="type.value"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button size="small" type="primary" icon="el-icon-search" @click="search">搜索</el-button>
        <el-button size="small" type="primary" icon="el-icon-plus" @click="handleEdit()">添加</el-button>
        <el-button size="small" type="success" icon="el-icon-open" @click="dialogUpdateStatusVisible = true">更新状态
        </el-button>
        <el-button size="small" type="danger" icon="el-icon-delete" @click="deleteMeetingRoom">删除
        </el-button>
      </el-form-item>
    </el-form>
    <!--列表-->
    <el-table size="small"
              :data="listData"
              highlight-current-row
              v-loading="loading"
              element-loading-text="拼命加载中"
              height="500"
              style="width: 100%;"
              @selection-change="handleSelectionChange">
      <el-table-column align="center" type="selection" width="60">
      </el-table-column>
      <el-table-column prop="roomCode" label="会议室编码" width="200">
      </el-table-column>
      <el-table-column prop="roomName" label="会议室名称" width="200">
      </el-table-column>
      <el-table-column sortable prop="roomType" label="会议室类型" width="200">
        <template slot-scope="scope">
          <div>{{scope.row.roomType == 1?'大型会议室':scope.row.roomType == 2?'中型会议室':'小型会议室'}}</div>
        </template>
      </el-table-column>
      <el-table-column sortable prop="enableStatus" label="会议室状态" width="200">
        <template slot-scope="scope">
          <div>{{scope.row.enableStatus == 1?'正常':'维护中'}}</div>
        </template>
      </el-table-column>
      <el-table-column prop="user.userName" label="会议室负责人" width="200">
      </el-table-column>
      <el-table-column sortable prop="createTime" label="创建时间" width="200">
        <template slot-scope="scope">
          <div>{{scope.row.createTime|timestampToTime}}</div>
        </template>
      </el-table-column>
      <el-table-column prop="creator" label="创建人" width="150">
      </el-table-column>
      <el-table-column sortable prop="modifiedTime" label="修改时间" width="200">
        <template slot-scope="scope">
          <div>{{scope.row.modifiedTime|timestampToTime}}</div>
        </template>
      </el-table-column>
      <el-table-column prop="modifier" label="修改人" width="150">
      </el-table-column>
      <el-table-column align="center" label="操作" width="150" fixed="right">
        <template slot-scope="scope">
          <el-button size="mini" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <Pagination v-bind:child-msg="pageparm" @callFather="callFather"></Pagination>
    <!-- 编辑界面 -->
    <el-dialog :title="title" :visible.sync="editFormVisible" width="30%" @click="closeDialog">
      <el-dialog
        width="50%"
        title="选择部门负责人"
        :visible.sync="innerVisible"
        append-to-body>
        <el-form :inline="true" :model="queryUserForm">
          <el-form-item label="搜索：">
            <el-input size="small" v-model="queryUserForm.userCodeOrName" placeholder="输入用户编码或名称" clearable></el-input>
          </el-form-item>
          <el-form-item>
            <el-button size="small" type="primary" icon="el-icon-search" @click="searchUser">搜索</el-button>
          </el-form-item>
        </el-form>
        <el-table
          ref="singleTable"
          :data="userList"
          highlight-current-row
          @current-change="handleCurrentChange"
          style="width: 100%"
          height="200"
          size="mini">
          <el-table-column
            type="index"
            label="序号"
            width="100"
            align="center">
          </el-table-column>
          <el-table-column
            property="userCode"
            label="用户编码"
            align="center">
          </el-table-column>
          <el-table-column
            property="userName"
            label="姓名"
            align="center">
          </el-table-column>
        </el-table>
        <!-- 分页组件 -->
        <Pagination v-bind:child-msg="pageparmUser" @callFather="callFatherUser"></Pagination>
        <div slot="footer" class="dialog-footer">
          <el-button size="small" @click="innerVisible = false">取消</el-button>
          <el-button size="small" type="primary" :loading="loading" class="title" @click="submitSelect">保存
          </el-button>
        </div>
      </el-dialog>
      <el-form label-width="120px" :model="editForm" :rules="rules" ref="editForm">
        <el-form-item label="会议室编码：" prop="roomCode">
          <el-input size="small" v-model="editForm.roomCode" auto-complete="off" placeholder="请输入会议室编码"></el-input>
        </el-form-item>
        <el-form-item label="会议室名称：" prop="roomName">
          <el-input size="small" v-model="editForm.roomName" auto-complete="off" placeholder="请输入会议室名称"></el-input>
        </el-form-item>
        <el-form-item label="会议室类型" prop="roomType">
          <el-select size="small" v-model="editForm.roomType" placeholder="请选择会议室类型" class="userRole" clearable>
            <el-option label="大型会议室" :value="1" :key="1"></el-option>
            <el-option label="中型会议室" :value="2" :key="2"></el-option>
            <el-option label="小型会议室" :value="3" :key="3"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="会议室负责人：" prop="userId">
          <el-input size="small" v-model="userName" auto-complete="off" placeholder="请选择会议室负责人" disabled>
            <el-button slot="append" @click="chooseUser" icon="el-icon-s-custom"></el-button>
          </el-input>
        </el-form-item>
        <el-form-item label="会议室说明：" prop="remark">
          <el-input size="small" v-model="editForm.remark" auto-complete="off" placeholder="请输入会议室说明"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" @click="closeDialog">取消</el-button>
        <el-button size="small" type="primary" :loading="loading" class="title" @click="submitForm('editForm')">保存
        </el-button>
      </div>
    </el-dialog>

    <el-dialog title="收货地址" :visible.sync="dialogUpdateStatusVisible" width="20%" center>
      <div style="text-align: center">
        <el-radio-group v-model="status">
          <el-radio :label="1">正常</el-radio>
          <el-radio :label="2">维护</el-radio>
        </el-radio-group>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogUpdateStatusVisible = false">取 消</el-button>
        <el-button type="primary" @click="updateStatus">确 定</el-button>
      </span>
    </el-dialog>

  </div>
</template>

<script>
    import Pagination from '../../components/Pagination'
    import {Get, Post} from "../../api/axiosFun";

    export default {
        data() {
            return {
                status: 1,
                dialogUpdateStatusVisible: false,

                nshow: true, //switch开启
                fshow: false, //switch关闭
                loading: false, //是显示加载
                editFormVisible: false, //控制编辑页面显示与隐藏
                userList: [],
                queryUserForm: {
                    pageIndex: 0,
                    pageSize: 10,
                    userCodeOrName: '', // 搜索用户
                },
                innerVisible: false,
                title: '添加',
                roomType: [
                    {key: '全部', value: ''},
                    {key: '大型会议室', value: 1},
                    {key: '中型会议室', value: 2},
                    {key: '小型会议室', value: 3}
                ],
                enableStatus: [
                    {key: '全部', value: ''},
                    {key: '正常', value: 1},
                    {key: '维护中', value: 2}
                ],
                userName: '',
                editForm: {
                    roomCode: '',
                    roomName: '',
                    roomType: '',
                    remark: '',
                    userId: '',
                },
                // rules表单验证
                rules: {
                    roomCode: [
                        {required: true, message: '请输入会议室编码', trigger: 'blur'}
                    ],
                    roomName: [
                        {required: true, message: '请输入会议室名称', trigger: 'blur'}
                    ],
                    roomType: [
                        {required: true, message: '请选择会议室类型', trigger: 'change'}
                    ],
                    userId: [
                        {required: true, message: '请选择会议室负责人', trigger: 'blur'}
                    ],
                    userId: [
                        {required: true, message: '请选择会议室负责人', trigger: 'change'}
                    ]
                },
                formInline: {
                    pageIndex: 0,
                    pageSize: 10,
                    roomCodeOrName: '',
                    roomType: '',
                    enableStatus: '',
                },
                // 删除部门
                selectdata: [],
                listData: [], //用户数据
                // 分页参数
                pageparm: {
                    currentPage: 1,
                    pageSize: 10,
                    total: 10
                },
                pageparmUser: {
                    currentPage: 1,
                    pageSize: 10,
                    total: 10
                }
            }
        },
        // 注册组件
        components: {
            Pagination
        },
        /**
         * 数据发生改变
         */

        /**
         * 创建完毕
         */
        created() {
            this.getdata(this.formInline)
        },

        /**
         * 里面的方法只有被调用才会执行
         */
        methods: {
            // 获取公司列表
            getdata(parameter) {
                this.loading = true
                Get("/officeSystem/meetingRoom/select", parameter)
                    .then(result => {
                        if(result.status == 200){
                            this.listData = result.data.resultList
                            this.pageparm.total = result.data.totalCount
                        }else{
                            this.listData = []
                            this.pageparm.total = result.data.totalCount
                        }
                    })
                this.loading = false
            },
            // 分页插件事件
            callFather(parm) {
                this.formInline.pageIndex = parm.currentPage-1
                this.formInline.pageSize = parm.pageSize
                this.getdata(this.formInline)
            },
            callFatherUser(parm) {
                this.queryUserForm.pageIndex = parm.currentPage - 1
                this.queryUserForm.pageSize = parm.pageSize
                this.searchUser(this.queryUserForm)
            },
            // 搜索事件
            search() {
                this.getdata(this.formInline)
            },
            //显示编辑界面
            handleEdit: function (index, row) {
                this.editFormVisible = true
                if (row != undefined && row != 'undefined') {
                    this.title = '修改'
                    this.editForm.roomCode = row.roomCode
                    this.editForm.roomName = row.roomName
                    this.editForm.roomType = row.roomType
                    this.editForm.remark = row.remark
                    this.editForm.userId = row.userId
                    this.userName = row.user.userName
                } else {
                    this.title = '添加'
                    this.editForm.roomCode = ''
                    this.editForm.roomName = ''
                    this.editForm.roomType = ''
                    this.editForm.remark = ''
                    this.editForm.userId = ''
                }
            },
            // 获取用户列表
            searchUser(){
                Get("/officeSystem/user/selectByCondition", this.queryUserForm)
                    .then(result => {
                        if(result.status == 200){
                            this.pageparmUser.total = result.data.totalCount;
                            this.userList = result.data.resultList
                        }else{
                            this.pageparmUser.total = result.data.totalCount;
                            this.userList = []
                        }
                    })
            },
            chooseUser(){
                this.searchUser()
                this.innerVisible = true
            },
            handleCurrentChange(val) {
                this.selectUser = val;
            },
            submitSelect(){
                this.userName = this.selectUser.userName
                this.editForm.userId = this.selectUser.id
                this.innerVisible = false
            },
            // 编辑、增加页面保存方法
            submitForm(editData) {
                this.$refs[editData].validate(valid => {
                  if (valid) {
                      if(this.title == '添加'){
                          Post("/officeSystem/meetingRoom/insert", this.editForm)
                              .then(result => {
                                  if(result.status == 200){
                                      this.$message.success(result.message);
                                      this.getdata(this.formInline);
                                      this.editFormVisible = false;
                                  }else{
                                      this.$message.error(result.message);
                                  }
                              })
                      }else{
                          Post("/officeSystem/meetingRoom/update", this.editForm)
                              .then(result => {
                                  if(result.status == 200){
                                      this.$message.success(result.message);
                                      this.getdata(this.formInline);
                                      this.editFormVisible = false;
                                  }else{
                                      this.$message.error(result.message);
                                  }
                              })
                      }
                  } else {
                    return false
                  }
                })
            },
            // 删除会议室
            deleteMeetingRoom() {
                if(this.selectdata.length == 0){
                    this.$message.warning("请选择要操作的数据");
                    return;
                }
                this.$confirm('此操作将永久删除选中会议室, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    let params = {
                        params: JSON.stringify(this.selectdata)
                    }
                    Post("/officeSystem/meetingRoom/delete", params)
                        .then(result => {
                            if(result.status == 200){
                                this.getdata(this.formInline)
                                this.$message.success(result.message)
                            }else {
                                this.$message.error(result.message)
                            }
                        })
                })
            },

            updateStatus(){
                this.dialogUpdateStatusVisible = false;
                if(this.selectdata.length == 0){
                    this.$message.warning("请选择要操作的数据");
                    return;
                }
                for(let i=0; i<this.selectdata.length; i++){
                    this.selectdata[i].enableStatus = this.status;
                }
                let params = {
                    params: JSON.stringify(this.selectdata)
                }
                Post("/officeSystem/meetingRoom/updateEnableStatus", params)
                    .then(result => {
                        if(result.status == 200){
                            this.getdata(this.formInline)
                            this.$message.success(result.message)
                        }else {
                            this.$message.error(result.message)
                        }
                    })
            },
            // 关闭编辑、增加弹出框
            closeDialog() {
                this.editFormVisible = false
            },
            handleSelectionChange(val){
                this.selectdata = val;
            }
        }
    }
</script>

<style scoped>
  .user-search {
    margin-top: 20px;
  }

  .userRole {
    width: 100%;
  }
</style>


